home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / COMPARE.AML < prev    next >
Text File  |  1996-07-17  |  3KB  |  132 lines

  1. //--------------------------------------------------------------------
  2. // COMPARE.AML
  3. // Compare Files, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Compare.dox for user help)
  6. //
  7. // This macro displays a dialog box which allows you to compare two
  8. // files, with various options. The Dos command 'fc' is used to perform
  9. // the comparision.
  10. //
  11. // Usage:
  12. //
  13. // Select this macro from the Macro List (on the Macro menu), or run it
  14. // from the macro picklist <shift f12>.
  15. //--------------------------------------------------------------------
  16.  
  17. include bootpath "define.aml"
  18.  
  19. variable file2, options
  20.  
  21. // set default filenames
  22. file1 = getbufname
  23. file2 = if _BackupDir then
  24.           qualify (getname file1) (qualify _BackupDir)
  25.         else
  26.           forceext file1 _BackupExt
  27.         end
  28.  
  29. macrofile = arg 1
  30.  
  31. // called by Lib.x when a key is entered in the dialog box
  32. function ondialog (keycode)
  33.   // macro help
  34.   if keycode == <f1> then
  35.     helpmacro macrofile
  36.   end
  37. end
  38.  
  39. // compare dialog box
  40. dialog "Compare Files" 65 10 "c"
  41. field "&Compare: >"  3  2 40 (onname file1) "_load"
  42. field "&With:    >"  3  4 40 (onname file2) "_load"
  43.  
  44. // initialize to previous options, if possible
  45. options = if variable? "cmpopt" 'prf' then
  46.             prf.cmpopt
  47.           else
  48.             "lo"
  49.           end
  50.  
  51. // compare options group box
  52. groupbox '' 3 6
  53.   (menu ''
  54.      item " [ ] Show &Line Numbers"
  55.      item " [ ] &Ignore Case"
  56.      item " [ ] Show &First and Last Lines Only "
  57.      item " [ ] Use &Open Files if Possible"
  58.    end) '' options "lifo"
  59.  
  60. // ok/cancel buttons
  61. button "O&k"      55 2 8
  62. button "Cancel"   55 4 8
  63.  
  64. // display dialog box and get control values
  65. if (getdialog ref file1 ref file2 ref options) == 'Ok' then
  66.  
  67.   // save options for next time
  68.   prf.cmpopt = options
  69.  
  70.   oldbuf = getcurrbuf
  71.  
  72.   // use open files
  73.   if pos 'o' options then
  74.  
  75.     // file 1
  76.     buffer = findbuf file1
  77.     if buffer then
  78.       oldfile1 = file1
  79.       file1 = (getpath file1) + "@@@@cmp1"
  80.       gotobuf buffer
  81.       ok = save file1
  82.       gotobuf oldbuf
  83.       if not ok then
  84.         msgbox "Save Error!"
  85.         return
  86.       end
  87.     end
  88.  
  89.     // file 2
  90.     buffer = findbuf file2
  91.     if buffer then
  92.       oldfile2 = file2
  93.       file2 = (getpath file2) + "@@@@cmp2"
  94.       gotobuf buffer
  95.       ok = save file2
  96.       gotobuf oldbuf
  97.       if not ok then
  98.         msgbox "Save Error!"
  99.         return
  100.       end
  101.     end
  102.   end
  103.  
  104.   // run the Dos 'FC' command and capture the output
  105.   runcap "fc " + file1 + ' ' + file2 +
  106.          (if? (pos 'l' options) ' /n') +
  107.          (if? (pos 'f' options) ' /a') +
  108.          (if? (pos 'i' options) ' /c')
  109.  
  110.   if getcurrbuf <> oldbuf then
  111.     // change temporary filenames back to actual filenames in
  112.     // the comparison report
  113.     if oldfile1 then
  114.       replace file1 oldfile1 '*ag'
  115.     end
  116.     if oldfile2 then
  117.       replace file1 oldfile2 '*ag'
  118.     end
  119.     // turn off the buffer modified flag
  120.     bufferflag '-m'
  121.   end
  122.  
  123.   // cleanup temporary files
  124.   if oldfile1 then
  125.     deletefile file1
  126.   end
  127.   if oldfile2 then
  128.     deletefile file2
  129.   end
  130.  
  131. end
  132.